import $ from 'jquery' 
import {message} from 'antd'

var b = function () {
    var url = window.location.href;
    var testReg = /http:\/\/wap.maidyx.com/g;
    var testPro = /http:\/\/pro-wap.maidyx.com/g;
    var res = testReg.test(url);
    var resPro = testPro.test(url);
    var head = {
        apiUrl: 'http://test-admin.maidyx.net/api/backend/',
        // apiUrl: 'http://heroapiadmin.com/api/backend/',
        avatar: 'https://test-image.maidyx.net/',
        loginView: (that)=>{
            return new Promise(resolve=>{
              $.ajax({
                type:'POST',
                url:head.apiUrl+'login_view',
                data:{
                  token:localStorage.token
                },
                success:(res)=>{
                  if(res.status ==1){
                      resolve(res)
                  }else{
                    message.error(res.msg+'111')
                    that.props.history.push("/")
                  }
                },
                error:(err)=>{
                    message.error(res.msg+"222")
                    that.props.history.push("/")
                }
              })
            })
          }
    }

    if (res) {
        head = {
            apiUrl: 'https://web.maidyx.com/',
            avatar: 'https://image.maidyx.com/',
            loginView: (that)=>{
              return new Promise(resolve=>{
                $.ajax({
                  type:'POST',
                  url:head.apiUrl+'login_view',
                  data:{
                    token:localStorage.token
                  },
                  success:(res)=>{
                    if(res.status ==1){
                        resolve(res)
                    }else{
                      message.error(res.msg)
                      that.props.history.push("/")
                    }
                  },
                  error:(err)=>{
                      message.error(res.msg)
                      that.props.history.push("/")
                  }
                })
              })
            }
        }
        return head
    }

    if (resPro) {
        head = {
            apiUrl: 'http://pro-web.maidyx.net/',
            avatar: 'http://pro-image.maidyx.net/',
            loginView: (that)=>{
              return new Promise(resolve=>{
                $.ajax({
                  type:'POST',
                  url:head.apiUrl+'login_view',
                  data:{
                    token:localStorage.token
                  },
                  success:(res)=>{
                    if(res.status ==1){
                        resolve(res)
                    }else{
                      message.error(res.msg)
                      that.props.history.push("/")
                    }
                  },
                  error:(err)=>{
                      message.error(res.msg)
                      that.props.history.push("/")
                  }
                })
              })
            }
        }
        return head
    }
    return head
}()

const apiUrl = b.apiUrl;
const avatar = b.avatar;
const loginView = b.loginView
export {
    apiUrl,
    avatar,
    loginView
}


//test-backstage.maidyx.net  测试